﻿#region File Description 
///////////////////////////////////////////////////////////////////////////////
/// \file GOLSprite.cs
/// \brief This file stores the Game Of Life Sprite Class, Simple GOL Node Cell.
/// \author Steven Duda
/// \date 14/5/2010
/// \remarks Copyright(c) 2010 LM01 Project Group (Animus Games - ViralFlux)
/// \remarks Some Rights Reserved.
/// Licenced under: Microsoft Reciprocal License (Ms-RL)
/// For More Information see: www.microsoft.com/opensource/licenses.mspx
///////////////////////////////////////////////////////////////////////////////
#endregion

#region Using Statements 
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
#endregion

namespace GameOfLife
{
    /// <summary>
    /// \class GOLSprite
    /// \author Steven Duda
    /// \brief Sprite for the Game of Life Program.
    /// This handles on/off texture setting. & Mouse Interactions
    /// </summary>
	internal sealed class GOLSprite : Sprite
    {
        private static GOLSprite instance = new GOLSprite();

        #region Fields

        internal bool IsOn { set; get; }
        internal static Texture2D onTexture { set; get; }
        internal static Texture2D offTexture { set; get; }

        #endregion 

		#region Constructors

		/// \brief Constructor, Creates the GOL Sprite with a specified State
        /// \author Steven Duda
        /// \param batch Reference to the SpriteBatch to use for Render
        /// \param initialPosition Vector2 initial position for the GOLSprite
        /// \param _isOn Status passed during construction (Default is false/off)
		internal GOLSprite(SpriteBatch batch, Vector2 initialPosition, bool _isOn)
            : base(batch, initialPosition)
        {
            IsOn = _isOn;
            if (_isOn)
                Texture = onTexture;
            else
                Texture = offTexture;
        }

        //null Constuctor (for singleton instancing)
        private GOLSprite() : base() { }

		#endregion

		#region Public Methods

		/// \brief Updates the GOL Sprite:
        /// 1. Check for MouseOver and Handle (if req.)
        /// 2. Change the TintColor to Maroon/Red if RightButton is Down.
        /// \author Steven Duda
        internal override void Update()
        {
            if (Enabled)
            {
                if (isMouseOver())
                {
                    if (MouseStateManager.RightButtonHeld())
                        TintColor = Color.Maroon;
                    else
                        TintColor = Color.SteelBlue;
                }
                else
                {
                    TintColor = Color.White;
                }
            }
        }

        /// \brief Draws the on/off texture to match the object status
        /// \author Steven Duda
        /// \note base.Draw is still called
        /// \note Enabled Disabling Draw is Optional
        internal override void Draw()
        {
            if (Enabled)
            {
                //Set the On or Off texture 
                #region Original Texture Update/Draw Method
                //if (IsOn)
                //    Texture = onTexture;
                //else
                //    Texture = offTexture;
                //base.Draw();
                #endregion

                #region More Efficient Version
                if (IsOn)
                    Batch.Draw(onTexture, Position, TintColor);
                else
                    Batch.Draw(offTexture, Position, TintColor);
                #endregion
            }
        }

        /// \brief Checks if the Left Mouse is pressed on the GOL Sprite
        /// \author Steven Duda
        /// \return Returns bool, Left Mouse Pressed on GOL Sprite? (true/false)
        internal bool isPressed()
        {
            return (isMouseOver() && MouseStateManager.LeftButtonPress());
        }

        /// \brief Checks if the Left Mouse is held down on the GOL Sprite
        /// \author Steven Duda
        /// \return Returns bool, Left Mouse held down On GOL Sprite? (true/false)
        internal bool isHeld()
        {
            return (isMouseOver() && MouseStateManager.LeftButtonHeld());
        }

        /// \brief Checks if the Right Mouse is held down on the GOL Sprite
        /// \author Steven Duda
        /// \return Returns bool, Right Mouse held down On GOL Sprite? (true/false)
        internal bool isRightHeld()
        {
            return (isMouseOver() && MouseStateManager.RightButtonHeld());
        }

        internal bool isMiddleReleased()
        {
            return (isMouseOver() && MouseStateManager.MiddleButtonRelease());
        }

        /// \brief Checks if the Mouse is hovering over the GOL Sprite
        /// \author Steven Duda
        /// \return Returns bool, Is Mouse Over GOL Sprite? (true/false)
        internal bool isMouseOver()
        {
            return (isInSprite(MouseStateManager.x, MouseStateManager.y));
        }

        #endregion 
    }
}


